﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInterface.h"

namespace gnuf
{
    enum class ResultTypeForProgress : std::uint8_t
    {
        eSuccess,
        eWarning,
        eError
    };
    struct GNUF_INTERFACE_EXPORT BoardParameter {
        typedef typename std::vector < std::pair < bool, std::wstring>> CarouselFrameSections;
        typedef typename std::vector <std::pair<bool, CarouselFrameSections>>CarouselFrames;

        int carouselFrameDisplayTime;
        CarouselFrames carouselFrames;
        std::wstring helpCaption;
        std::wstring helpHyperlink;
        bool cancelable;
        bool waitForConfirmingAfterFinished;
    };
    class GNUF_INTERFACE_EXPORT ProgressBarInterface
    {
    public:
        static ProgressBarInterface* Get();
        static void SetDefaultCarouselFrames(const BoardParameter& carousel) { m_carouselFarmes = carousel; }

    public:
        /// \ summary 启动进度条ProgressBar
        /// minimun 进度条的最小值
        /// maximum 进度条的最大值
        /// text 进度条左侧显示的文字信息
        /// wantAutoBeginChildProgress 是否自动启动ChildProgress, 
        ///                            为true，无需手动调用BeginChildProgress
        ///                            为false, 可以手动调用BeginChildProgress来切分子过程
        virtual void ShowProgress(
            int minimun = 0,
            int maximum = 100,
            const std::wstring& text = L"",
            bool wantAutoBeginChildProgress = true) = 0;

        /// \summary 启动进度板ProgressBoard
        /// \param minimun 进度条的最小值
        /// \param maximun 进度条的最大值
        /// \param format 进度条的模式 // 0:percentage, 1:value, 2:mode
        /// \param doingWhat 进度条的任务概述
        /// \param message 进度条的任务详细描述
        /// \param wantAutoBeginChildProgress 是否自动启动ChildProgress, 
        ///                                   为true, 无需手动调用BeginChildProgress
        ///                                   为false, 可以手动调用BeginChildProgress来切分子过程
        /// \param work 进度条运行过程中， 后台进行的任务
        virtual void ShowProgress(
            int minimun = 0,
            int maximum = 100,
            int format = 0,
            const std::wstring& doingWhat = L"",
            const std::wstring& message = L"",
            bool wantAutoBeginChildProgress = true,
            const std::function<void()>& work = nullptr) = 0;

        //设置进度条的值为value，进度条应该监听ProgressReporter的进度， 不建议调用该函数 
        virtual void SetProgress(int value) = 0;

        // 结束进度条
        virtual void EndProgress() = 0;

        // 开启子进度
        // 
        //       A                 B
        //  |---------|--------------------------|
        //  1   1秒   2            3秒           3
        // 
        // 在 1 的位置调用BeginChildProgress(0,25)
        // 在 2 的位置调用EndChildProgress(); BeginChildProgress(25,100)
        //
        virtual void BeginChildProgress(double start, double end) = 0;

        virtual void EndChildProgress() = 0;

        // 任务结束时 弹出的弱提示框信息
        virtual void SetResult(ResultTypeForProgress resultType, const std::wstring& text) = 0;

        // 设置进度板上的信息 
        virtual void SetMessage(const std::wstring& message) = 0;

    protected:
        ProgressBarInterface() {}

        // 此接口由UI框架调用，外部不可调用。
        // 如必须调用，请联系wuzx-d@glodon.com
        void SetInterface(ProgressBarInterface*);

        static BoardParameter m_carouselFarmes;

    private:
        ProgressBarInterface(const ProgressBarInterface&) = delete;
        ProgressBarInterface(ProgressBarInterface&&) = delete;
        ProgressBarInterface& operator=(const ProgressBarInterface&) = delete;
    };
}
